Ext.onReady(function(){   
    var Tree = Ext.tree;    
    tree = new Tree.TreePanel({   
        el:'tree-div',   
        useArrows:true,   
        autoScroll:true,  
      	height:document.body.offsetHeight,
      	width:document.body.offsetWidth,
        onlyLeafCheckable: false,//对树所有结点都可选 
        animate:true,   
        checkModel: 'single',   //对树的级联多选 
        enableDD:true,   
        rootVisible: false,       
       animCollapse: false,
        loader: new Tree.TreeLoader({   
            dataUrl:'tagTree.htm?action=tagTree1' ,
            baseParams:{parentId:0} ,
            baseAttrs: { uiProvider: Ext.tree.TreeCheckNodeUI } //添加 uiProvider 属性   
        })   
    });   
    	
    	/***把已经选择上的设置成true*******/
    	/*tree.on("append",function(tree,parent,node,index){
    		if(node != null)
	    	if(isChN)
	         {
	         	if(isChN(node.id))
	         	{
	         		node.attributes.checked = true; 	
			    }
			  }
    	});
    	*/
    	tree.on('beforeclick',function(node,e){

        	Ext.getDom(node.id+'-a').checked = true;
        	var nodeType = node.attributes.nodeType; 
        	if(1 == nodeType){
        		parent.frames["subjects"].document.getElementById("comeFromId").value= node.id;
        	}
        	if(2 == nodeType){
        		parent.frames["subjects"].document.getElementById("studyTagId").value = node.id;
        	}
        	if(3 == nodeType){
        		parent.frames["subjects"].document.getElementById("reasearchNavId").value = node.id;
        	}
        	if(4 == nodeType){
        		parent.frames["subjects"].document.getElementById("reasearchPropId").value = node.id;
        	}
        	 
        	E.onclick();
           
        	}); 
    	 tree.on('dblclick',function(node,e){
			Ext.getDom(node.id+'-a').checked = false;
			var nodeType = node.attributes.nodeType;  
        	if(1 == nodeType){ 
        		parent.frames["subjects"].document.getElementById("comeFromId").value ='';
        	}
        	if(2 == nodeType){
        		parent.frames["subjects"].document.getElementById("studyTagId").value ='';
        	}
        	if(3 == nodeType){
        		parent.frames["subjects"].document.getElementById("reasearchNavId").value ='';
        	}
        	if(4 == nodeType){
        		parent.frames["subjects"].document.getElementById("reasearchPropId").value ='';
        	}
        
        	});
        tree.on("beforeload", function(treeLoader, node) {
         //   alert(treeLoader.id);
	 		tree.loader.baseParams.parentId = treeLoader.id;
    	}, this);
     
      /* tree.on('checkchange', function(node, checked) {   
        if(!checked){
          if(parent.frames["subjects"].document.all.comeFromId.value == node.id){
              parent.frames["subjects"].document.all.comeFromId.value = '';
          }
          if(parent.frames["subjects"].document.all.studyTagId.value == node.id){
              parent.frames["subjects"].document.all.studyTagId.value = '';
          }
          if(parent.frames["subjects"].document.all.reasearchNavId.value == node.id){
              parent.frames["subjects"].document.all.reasearchNavId.value = '';
          }
          if(parent.frames["subjects"].document.all.reasearchPropId.value == node.id){
              parent.frames["subjects"].document.all.reasearchPropId.value = '';
          }
        
        }
        node.expand();      
        node.attributes.checked = checked;   
        node.eachChild(function(child) {      
            child.ui.toggleCheck(checked);      
            child.attributes.checked = checked;      
            child.fireEvent('checkchange', child, checked);      
        });      
    }, tree);     
     */
    // set the root node   
    var root = new Tree.AsyncTreeNode({   
        text: '课题分类', 
        //checked:true,  
        draggable:false,   
        id:'0'  
    });   
    tree.setRootNode(root);   
 
    // render the tree   
    tree.render();   
    //root.expand();   
     tree.expandAll();
});  
     
   
   
